<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* 
* Module default for frontpage
* @author DANG DINH HUNG
*
*/
class Buyer extends Public_Controller
{
	var $task= "";
	public function __construct()
	{
		parent::__construct();
		$this->load->model('buyer_m'); 
		
		$this->show_entity->changeStatusOfShowOutOfBid();
		
		$this->buyer_m->authorization();
		
		$this->task = $this->uri->segment(3,'');
		$this->data->navigator = $this->_buildMenu();	
		$this->data->phpJS = php2js();
		
		$this->template->append_metadata("<script src='".site_url()."addons/default/themes/sbx/js/md5.js"."' ></script>");
		$this->template->append_metadata("<script src='".site_url()."addons/default/themes/sbx/js/buyer.js"."' ></script>");	
	//	$this->template->append_metadata("<script src='".site_url()."addons/default/themes/sbx/js/date.js"."' ></script>");
	}
	
	private function _buildMenu(){
		return $this->buyer_m->_buildMenu($this->task);	
	}
	
	public function index()
	{
		redirect("buyer/shows");
		$this->data->record_array = $this->buyer_m->index();
		$this->template
			->build('index', $this->data);
	}
	
	function dispute(){
		redirect(site_url('buyer'));
	}
	
	function my_account(){
		$this->load->model('account_m'); 
		switch($this->task){
			default:
				$this->data->items = $this->account_m->index();
				$this->template
					->build('account/index', $this->data);
				break;
			case 'edit_information':
				$this->data->items = $this->account_m->index();
				$this->template
					->build('account/edit_information', $this->data);
				break;
			case 'submit_information':
				$this->account_m->submit_information();
				break;
			case 'edit_information_notify':
				$this->template
					->build('account/edit_information_notify', $this->data);
				break;
			case 'change_password':
				$this->data->items = $this->account_m->index();
				$this->template
					->build('account/change_password', $this->data);
				break;
			case 'submit_password':
				$this->account_m->submit_password();
				break;
			case 'change_password_notify':
				$this->template
					->build('account/change_password_notify', $this->data);
				break;
			case 'change_email':
				$this->template
					->build('account/change_email', $this->data);
				break;
			case 'submit_email':
				$this->account_m->submit_email();
				break;
			case 'change_email_notify':
				$this->template
					->build('account/change_email_notify', $this->data);
				break;
		}
	}
	
	function shows(){
		$this->load->model('shows_m');
		
		switch($this->task){
			default:
				$this->data->items = $this->shows_m->index();
				$this->template->build('shows/index', $this->data);
				break;
			case 'search':
				$this->data->items = $this->shows_m->search();
				$this->template->build('shows/index', $this->data);
				break;
			case 'view':
				$this->data->items = $this->shows_m->view();
				$this->template->build('shows/view', $this->data);
				break;
			case 'bid':
				$this->data->items = $this->shows_m->bid();
				$this->template->build('shows/bid', $this->data);
				break;	
			case 'ajax_changeCountry':
				$this->shows_m->ajax_changeCountry();
				break;
			case 'ajax_changeZone':
				$this->shows_m->ajax_changeZone();
				break;
			case 'ajax_addBookingfor':
				$this->data->items = $this->shows_m->ajax_addBookingfor();
				$this->load->view('shows/ajax_addBookingfor', $this->data);
				break;
			case 'submit_bid':
				$this->shows_m->submit_bid();
				break;
			case 'bid_notify':
				$this->template->build('shows/bid_notify', $this->data);
				break;	
			case 'edit_bid':
				$this->data->items = $this->shows_m->edit_bid();
				$this->template->build('shows/edit_bid', $this->data);
				break;	
			case 'removeBooking':
				$this->shows_m->removeBooking();
				break;
			case 'submit_edit_bid':
				$this->shows_m->submit_edit_bid();
				break;
			case 'edit_bid_notify':
				$this->template->build('shows/edit_bid_notify', $this->data);
				break;	
			case 'submitQuestionSeller':
				$this->shows_m->submitQuestionSeller();
				break;
		}		
	}
	
	function search(){
		php2js();
		$this->load->model('myshows_m');
		
		$this->data->items = $this->myshows_m->search();
		$this->template->build('my_shows/index', $this->data);
	}
	
	function my_bids(){
		$this->load->model('mybids_m');
		switch($this->task){
			case 'all_bids':
			default:
				$this->data->items = $this->mybids_m->all_bids();
				break;
			case 'active_bids':
				$this->data->items = $this->mybids_m->active_bids();
				break;
			case 'awarded_bids':
				$this->data->items = $this->mybids_m->awarded_bids();
				break;
			case 'search':
				$this->data->items = $this->mybids_m->search();
				break;
			case 'delete_bid':
				$this->mybids_m->delete_bid();
				break;
		}		
		
		$this->template->build('my_bids/index', $this->data);
	}
	
/**	function show_manage(){
		$USER = $this->user_entity->init('id', $_SESSION['user']['id']);
		$SHOW = $this->show_entity->init('id', intval($this->input->get('show_id',''))) or show_404();
		
		if( $SHOW->getUserCreatedId() != $USER->getId() ){
			show_404();exit();
		}
		
		$this->load->model('showmanage_m');
		
		switch($this->task){
			default:
			case 'view_edit':
				$this->data->items = $this->showmanage_m->view_edit();
				$this->template->build('show_manage/view_edit', $this->data);
				break;
			case 'edit_show':
				$this->data->items = $this->showmanage_m->view_edit();
				$this->template->build('show_manage/edit_show', $this->data);
				break;
			case 'edit_show_notify':
				$this->template->build('show_manage/edit_show_notify', $this->data);
				break;
		}
	}
**/	
}